package com.cskaoyan.controller.admincontroller;

import com.cskaoyan.bean.po.MarketIssue;
import com.cskaoyan.bean.common.BasePageInfo;
import com.cskaoyan.bean.common.BaseRespVo;
import com.cskaoyan.bean.common.CommonData;
import com.cskaoyan.service.adminservice.IssueService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @author 楚夏三分
 * @datetime 2022/12/29 15:44
 * @description: TODO:
 */
@RestController
@RequestMapping("admin/issue")
public class IssueController {
    @Autowired
    IssueService issueService;

    /**
     * TODO: 查询问题列表
     * @param info 分页信息
     * @param question 问题模糊查询关键字
     * @return
     */
    @RequestMapping("list")
    public BaseRespVo list(BasePageInfo info,String question){
        CommonData<MarketIssue> data = issueService.list(info,question);
        return BaseRespVo.ok(data);
    }

    /**
     * TODO: 新增问题issue
     * @param map 问题及解答map
     * @return
     */
    @RequestMapping("create")
    public BaseRespVo create(@RequestBody Map map){
        String question = (String) map.get("question");
        String answer = (String) map.get("answer");
        MarketIssue marketIssue = issueService.create(question,answer);
        return BaseRespVo.ok(marketIssue);
    }

    /**
     * TODO: 编辑问题, 更新updateTime
     * @param issue 问题json对象
     * @return
     */
    @RequestMapping("update")
    public BaseRespVo update(@RequestBody MarketIssue issue){
        // MarketIssue issue = new MarketIssue();
        // issue.setDeleted(false);
        // issue.setId(createVO.getId());
        // issue.setQuestion(createVO.getQuestion());
        // issue.setAnswer(createVO.getAnswer());
        // issue.setAddTime(createVO.getAddTime());
        // issue.setUpdateTime(createVO.getUpdateTime());
        MarketIssue marketIssue = issueService.update(issue);
        return BaseRespVo.ok(marketIssue);
    }

    @RequestMapping("delete")
    public BaseRespVo delete(@RequestBody Map map){
        Integer id = (Integer) map.get("id");
        issueService.delete(id);
        return BaseRespVo.ok();
    }
}
